home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 7 / Eagles_Nest_Mac_Collection_Disc_7.TOAST / Text Editors & Tools / DocViewer111 / Apple DocViewer v1.1.1 / DocViewer Apple Events Info / DocViewer Lookup TechNote next >
Text File  |  1994-03-01  |  18KB  |  25 lines

  1. #004 New Apple Event Support in DocViewer 1.1.1 IntroductionBeginning with version 1.1.1, Apple DocViewer supports a special Apple event.  This Apple event is known as the "DocViewer Lookup" event.  With this event, it is possible to send a message to DocViewer requesting that it open a particular document and turn to a specific heading.  This DocViewer Tech Note describes the implementation of this event.  Please note that tech notes 1 - 3 do not address the Viewer portion of DocViewer and are only available to licensees of the Apple DocViewer Builder.DocViewerLookup.hAccompanying this Tech Note is a C header file for many of the constants and data structures  you will need when interacting programmatically with DocViewer.Event ParametersThe Lookup event accepts three parameters.  These parameters are encapsulated into a single data structure for this version.  (We will parameterize them at the Apple event level for the next release.)  This data structure is the only parameter of the Apple event.  The structure is defined as:typedef    struct {    FSSpec    aDoc;            //    FSSpec for the Doc to open/search    Str255    aPattern;    //    String in heading to find (length                                 // prefixed)    short        accessLevel;//    find level }SeekParamRec, *SeekParamRecPtr, **SeekParamRecHandle;The first parameter is an FSSpec to the document you wish to open and perform the lookup in.  DocViewer will open this document if it isn't already open.  This document must be a DocViewer document (Creator: HLX2 Type:ONLN.)  If you pass a document that does not belong to DocViewer, it will return a kWrongFileType in the 'errn' parameter of the Apple event reply.  The second parameter is the heading you wish DocViewer to look for.  This is a simple Pascal-style string with a maximum length of 255 characters.  DocViewer uses this string as a pattern to match against the document's Table of Contents.  The comparison is accomplished without regard to case or diacritical marks. (e.g. FAT == fAt,  fåt = fat).  If the string you pass in isn't found in the document's Table of Contents, then DocViewer will return a kEntryNotFound error.The third and final parameter is used to qualify the search pattern in the second parameter.  Once DocViewer has located the entry in the Table of Contents it will confirm that the entry is in the level of the TOC hierarchy specified in the accessLevel field.  DocViewer supports seven levels of hierarchy.  They are defined as follows:#define        kFirstLevelHier            1#define        kSecondLevelHier        2#define        kThirdLevelHier            3#define        kFourthLevelHier        4#define        kFigureLevelHier        201#define        kListLevelHier                202#define        kTableLevelHier            203An eighth constant has been defined that will allow the entry to be found at any level in the hierarchy.  In this case, if there are duplicate entries the first entry will be chosen.#define        kAnyLevelHier                999Each of these selectors is mutually exclusive, and they cannot be combined (or'd) together.Sending The EventLaunch DocViewer with DocumentThe first step when sending the lookup event is to see if DocViewer is currently running.  This can be accomplished with the Process manager GetProcessInfo routine.  If DocViewer is found in the list of currently running processes, you should check to see that the version of DocViewer is correct (1.1.1).  This can be done using the 'vers' resource with ID #1. If DocViewer is not running, it is necessary to launch the application with the target document.  If DocViewer is launched without reference to the target document, it will present its default SFGetFile dialog, and you will not be able to message the application until the dialog is dismissed.  For information on launching an application with a document see "LaunchwithDoc" on the latest version of the Developer CD (Tool Chest Edition).Again, when you launch the application, it is necessary to confirm that you are launching the correct version by checking the contents of the 'vers' ID #1 resource of the DocViewer application.Send the EventOnce you have determined that DocViewer is running (or you've launched it) you can then send the event.  See listing 1 for an example of sending the 'seek' event.Check for ErrorsIf DocViewer cannot find the entry requested, it will return an error in the reply of the Apple event.  See listing 1 for an example of how to determine these errors.Listing 1 - Sending the 'seek' Apple event//OpenDoc// This routine takes a pointer to a SeekParamRec// and sends it to DocViewer.  This routine assumes// that you've already checked to see if DocViewer is running// I removed most the error checking where it was obvious// to improve readability.OSErr OpenDoc(SeekParamRec *qData){    OSErr                        err = noErr;    AppleEvent        myEvent, reply;    AEDesc                    myAddress;    long                        appSig = kDocViewerAppSig;    long                        replyError = noErr;    Size                        actualSize;    DescType                gotType;        err = AECreateDesc(    typeApplSignature,(Ptr)&appSig,                        sizeof(appSig),&myAddress);        err = AECreateAppleEvent(kDocViewerEventClass, kSeekEventID,                                                                         &myAddress, kAutoGenerateReturnID,                                                                         kAnyTransactionID, &myEvent );                                err = AEPutParamPtr( &myEvent, keySeekParam, typeWildCard,                                                             (Ptr)qData, sizeof(SeekParamRec) );    err = AESend( &myEvent, &reply, kAEWaitReply,                                                 kAENormalPriority, kAEDefaultTimeout,                                         nil, nil );   // Check to see if you got an error    err = AEGetParamPtr( &reply, keyErrorNumber, typeLongInteger,                                                             &gotType, (Ptr)&replyError,                                                          sizeof(long), &actualSize);    // Special case on AEDescNotFound because we'll get an error    // if there is no error in the reply.    if ((err != noErr) && (err != errAEDescNotFound))    {        return err;    }    // if there's an error from DocViewer return it.    // otherwise return noErr.    if (replyError != noErr)            return replyError;    else            return noErr;}Ãdˇ ˇˇˇˇd°d WORDE 
  2. N~ìH åå@°ñ ,2hAppleGaramond Bd2h.ˇE E °dONLNdˇˇ+±Apple DocViewer†ó°ñ °dONLNdˇˇ(ÖflTechnical Note†ó°ñ ,2gAppleGaramond Bk2gã`(HÇã`°dONLNdˇˇ*' Apple Computer, Inc., Developer Press†óê    häà™¸¸˛ˇ¸ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛ˇˇˇ˛?ˇˇ¯ˇ¯ˇ¯ˇ¯ˇ¯ˇ¯¯8ê    häà™¸¸@Ä¿¿«·¿Δ«¿«¡¿ ¿«ÅΔ¿Δ!¿QΔ«…¿%¿‡¿ˇ¸˛ˇ˙˛%įÄ8888ˇ8¯8
  3. _, Palatino.°dONLNd≠~¡(º~/#004 New Apple Event Support in DocViewer 1.1.1°dONLNd2„ZÛ©(ÔZ Introduction °dONLNd?˘~ú+$.Beginning with version 1.1.1, Apple DocViewer °dONLNdm˘ú(úsupports a special°dONLNdÄ~g(~(Apple event.  This Apple event is known °dONLNd®g)Èas the "DocViewer Lookup"°dONLNd¬~#(~event.  With this event, °dONLNd€#)à-it is possible to send a message to DocViewer°dONLNd    #~1›(-~<requesting that it open a particular document and turn to a °dONLNdE#›1(-›specific°dONLNdN1~?/(;~heading.  This DocViewer Tech °dONLNdl1/?)±$Note describes the implementation of°dONLNdë?~MT(I~)this event.  Please note that tech notes °dONLNd∫?TM)÷1 - 3 do not address the Viewer°dONLNd⁄M~[(W~portion of DocViewer and °dONLNdÛM[)î,are only available to licensees of the Apple°dONLNd [~iÏ(e~DocViewer Builder.°dONLNd3wZá‹(ÉZDocViewerLookup.h °dONLNdEç~õfi+$>Accompanying this Tech Note is a C header file for many of the°dONLNdÑõ~©“*=constants and data structures  you will need when interacting°dONLNd¬©~∑B* programmatically with DocViewer.°dONLNd„≈Z’À(—ZEvent Parameters °dONLNdÙ€~ÈÓ+$@The Lookup event accepts three parameters.  These parameters are°dONLNd5È~˜Ô*Eencapsulated into a single data structure for this version.  (We will°dONLNd{˜~*Gparameterize them at the Apple event level for the next release.)  This°dONLNd√~*Gdata structure is the only parameter of the Apple event.  The structure°dONLNd ~!≈*is defined as:,
  4. Courier
  5. °dONLNd'~3®*typedef°dONLNd"'¥3‰)6struct {°dONLNd,8¢DΔ(A¢FSSpec°dONLNd38ÿDˆ)6aDoc;°dONLNd;8 D,)H//°dONLNd>82D¯)!FSSpec for the Doc to open/search°dONLNdaI¢UΔ(R¢Str255°dONLNdhIÿU)6    aPattern;°dONLNdrI U,)H//°dONLNduI2U˛)"String in heading to find (length °dONLNdüT `h(]  // prefixed)°dONLNd≠e¢q¿(n¢short°dONLNd¥eÿq,)6accessLevel;//°dONLNd√e2qn)Z
  6. find level°dONLNdœv~Ǭ(~6}SeekParamRec, *SeekParamRecPtr, **SeekParamRecHandle; °dONLNdá~ïÚ*AThe first parameter is an FSSpec to the document you wish to open°dONLNdHï~£¸*Cand perform the lookup in.  DocViewer will open this document if it°dONLNdå£~±Ù*?isn't already open.  This document must be a DocViewer document°dONLNdñ~ø*(Creator: HLX2 Type:ONLN.)°dONLNdÊƺ!(∏ °dONLNdÁ±!øÓ+% If you pass a document that does notˇpdˇ ˇˇˇˇd
  7. _, Palatino .°dONLNdH~VL+~R&belong to DocViewer, it will return a ,
  8. Courier
  9. °dONLNd&ILU¶)ŒkWrongFileType  °dONLNd5H¶VÍ)Zin the 'errn'°dONLNdCV~dD(`~#parameter of the Apple event reply.°dONLNdij~x*CThe second parameter is the heading you wish DocViewer to look for.°dONLNdÆx~ÜË*AThis is a simple Pascal-style string with a maximum length of 255°dONLNdÜ~îÚ*Echaracters.  DocViewer uses this string as a pattern to match against°dONLNd6î~¢¯*Athe document's Table of Contents.  The comparison is accomplished°dONLNdx¢~∞˝*Kwithout regard to case or diacritical marks. (e.g. FAT == fAt,  fåt = fat).°dONLNd≈∞~æÿ*@If the string you pass in isn't found in the document's Table of°dONLNdæ~Ã]*'Contents, then DocViewer will return a 
  10. °dONLNd-ø]À∑)flkEntryNotFound  °dONLNd<æ∑Ã÷)Zerror.°dONLNdC“~‡˘(‹~FThe third and final parameter is used to qualify the search pattern in°dONLNdä‡~ÓÙ*Bthe second parameter.  Once DocViewer has located the entry in the°dONLNdÕÓ~¸Û*GTable of Contents it will confirm that the entry is in the level of the°dONLNd¸~
  11. )*TOC hierarchy specified in the 
  12. °dONLNd4˝)    k)´ accessLevel °dONLNd?¸k
  13. )B field.  DocViewer supports°dONLNd[
  14. ~¨(~8seven levels of hierarchy.  They are defined as follows:
  15. °dONLNdî~*®*#define°dONLNdù¥*)6kFirstLevelHier°dONLNdØ2*8)~1°dONLNd±)~5®(2~#define°dONLNd∫)¥5)6kSecondLevelHier°dONLNdÃ)258)~2°dONLNdŒ4~@®(=~#define°dONLNd◊4¥@)6kThirdLevelHier°dONLNdÈ42@8)~3°dONLNdÎ?~K®(H~#define°dONLNdÙ?¥K)6kFourthLevelHier°dONLNd?2K8)~4°dONLNdJ~V®(S~#define°dONLNdJ¥V)6kFigureLevelHier°dONLNd#J2VD)~201°dONLNd'U~a®(^~#define°dONLNd0U¥a)6kListLevelHier°dONLNdBU2aD)~202°dONLNdF`~l®(i~#define°dONLNdO`¥l)6kTableLevelHier°dONLNda`2lD)~203 °dONLNdeq~Ô({~CAn eighth constant has been defined that will allow the entry to be°dONLNd©~ç˝*Jfound at any level in the hierarchy.  In this case, if there are duplicate°dONLNdÙç~õG*'entries the first entry will be chosen.
  16. °dONLNd°~≠®*#define°dONLNd%°¥≠)6kAnyLevelHier°dONLNd6°2≠D)~999 °dONLNd:≤~¿‡(º~AEach of these selectors is mutually exclusive, and they cannot be°dONLNd|¿~Œ *combined (or'd) together.°dONLNdñ‹ZÏ—(ËZSending The Event °dONLNd®Ú~D+$Launch DocViewer with Document°dONLNd«~*FThe first step when sending the lookup event is to see if DocViewer is°dONLNd~"÷*=currently running.  This can be accomplished with the Process°dONLNdL"~0≤*manager 
  17. °dONLNdT#≤/)4GetProcessInfo °dONLNdb"0¸)T/ routine.  If DocViewer is found in the list of°dONLNdí0~>˛(:~Ecurrently running processes, you should check to see that the version°dONLNdÿ>~L·*Cof DocViewer is correct (1.1.1).  This can be done using the 'vers'°dONLNdL~ZÓ*resource with ID #1.°dONLNd2`~n˙*FIf DocViewer is not running, it is necessary to launch the application°dONLNdyn~|–*;with the target document.  If DocViewer is launched without°dONLNdµ|~ä¯*Greference to the target document, it will present its default SFGetFile°dONLNd˝ä~òÛ*Edialog, and you will not be able to message the application until the°dONLNdCò~¶Í*Adialog is dismissed.  For information on launching an application°dONLNdÖ¶~¥Ò*@with a document see "LaunchwithDoc" on the latest version of the°dONLNdΔ¥~¬B*"Developer CD (Tool Chest Edition).ˇ>dˇ ˇˇˇˇd
  18. _, Palatino .°dONLNdH~VÌ+~RBAgain, when you launch the application, it is necessary to confirm°dONLNdCV~dˇ*Fthat you are launching the correct version by checking the contents of°dONLNdäd~rÆ*7the 'vers' ID #1 resource of the DocViewer application.°dONLNd¬x~Ü”*Send the Event°dONLNd—å~öÍ*=Once you have determined that DocViewer is running (or you've°dONLNdö~®*Glaunched it) you can then send the event.  See listing 1 for an example°dONLNdW®~∂*of sending the 'seek' event.°dONLNdtº~ ÿ*Check for Errors°dONLNdÖ–~fi*HIf DocViewer cannot find the entry requested, it will return an error in°dONLNdŒfi~ÏÛ*Ethe reply of the Apple event.  See listing 1 for an example of how to°dONLNdÏ~˙ˇ*determine these errors.    °dONLNd,ˇ~**Listing 1 - Sending the 'seek' Apple event,
  19. Courier
  20. °dONLNdW ~¥*    //OpenDoc°dONLNda~"§* 1// This routine takes a pointer to a SeekParamRec°dONLNdì!~-∞* 3// and sends it to DocViewer.  This routine assumes°dONLNd«,~8Ï* =// that you've already checked to see if DocViewer is running°dONLNd7~C‘* 9// I removed most the error checking where it was obvious°dONLNd?B~N* // to improve readability.°dONLNdZM~YJ* "OSErr OpenDoc(SeekParamRec *qData)°dONLNd}X~dÑ* {°dONLNdÄcêoÆ+ OSErr°dONLNdãc·o))Q err = noErr;°dONLNdônêzÃ(wê
  21. AppleEvent°dONLNd•n·z;)QmyEvent, reply;°dONLNd∂yêÖ¥(ÇêAEDesc°dONLNd¡y·Ö)Q
  22. myAddress;°dONLNdÕÑêê®(çêlong°dONLNd◊Ñ·ê})QappSig = kDocViewerAppSig;°dONLNdÛèêõ®(òêlong°dONLNd˝è·õS)QreplyError = noErr;°dONLNdö궮(£êSize°dONLNdö·¶#)Q actualSize;°dONLNd)•ê±¿(ÆêDescType°dONLNd5•·±)QgotType;°dONLNdAªê«(ƒêerr = AECreateDesc(°dONLNdUª«»)~typeApplSignature,(Ptr)&appSig,°dONLNd{ΔΩ“_(œΩsizeof(appSig),&myAddress);°dONLNdö‹ê˯(Âê<err = AECreateAppleEvent(kDocViewerEventClass, kSeekEventID,°dONLNdÍÁ)Ûı+ô "&myAddress, kAutoGenerateReturnID,°dONLNd Ú)˛›* kAnyTransactionID, &myEvent );°dONLNdHêÚ(ê;err = AEPutParamPtr( &myEvent, keySeekParam, typeWildCard, °dONLNdí‡+~ #(Ptr)qData, sizeof(SeekParamRec) );°dONLNd∑)ê5§(2ê.err = AESend( &myEvent, &reply, kAEWaitReply, °dONLNdÒ4·@ø+Q %kAENormalPriority, kAEDefaultTimeout,°dONLNd"?·K#* nil, nil );°dONLNd.U~ab(^~&   // Check to see if you got an error°dONLNdV`êl˛+ =err = AEGetParamPtr( &reply, keyErrorNumber, typeLongInteger,°dONLNd£kw∞+~ &gotType, (Ptr)&replyError,°dONLNd≈vΩÇ…(Ω  °dONLNdœvÇ∞)Qsizeof(long), &actualSize);°dONLNdÏÅêç¯(äê<// Special case on AEDescNotFound because we'll get an error°dONLNd*åêòn* %// if there is no error in the reply.°dONLNdQóê£∂* 1if ((err != noErr) && (err != errAEDescNotFound))°dONLNdÑ¢êÆñ* {°dONLNdà≠ôπ€+     return err;°dONLNdï∏êƒñ(¡ê}ˇúdˇ ˇˇˇˇd
  23. _,
  24. Courier
  25. .°dONLNdHêT∞+êQ0// if there's an error from DocViewer return it.°dONLNd2Sê_,* // otherwise return noErr.°dONLNdN^êj * if (replyError != noErr)°dONLNdji¢u+ return replyError;°dONLNd~têÄ®(}êelse°dONLNdÜ¢ã+ return noErr;°dONLNdîä~ñÑ(ì~}ˇ